package com.powersys.I18N;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

public class Filet {
	/**
	 * ·��ƴ��
	 * @return
	 */
	public static String pathMerge(String... path){
		
		if(path!=null && path.length>1 ){
			String old="";
			String news="";
			StringBuilder sb=new StringBuilder("");
			for (int i = 0; i < path.length-1; i++) {
				old=path[i].lastIndexOf("/")==path[i].length()-1?path[i]:path[i]+"/";
				sb.append(old);
				int index=path[i+1].lastIndexOf("/");
				news=index>0?path[i+1].substring(0, index):path[i+1];
				sb.append(news);
			}
			return sb.toString();
		}else{
			return path[0];
		}
		
	}
	
	public static String getProjectBasePath(Class cls){
		String path=cls.getResource("/").toString().replace("file:", "");
		if(path.startsWith("/")){
			path=path.substring(1);
		}
		if(path.contains("WEB-INF")){
			path=path.substring(0,path.indexOf("/WEB-INF"));
		}
		try {
			path=URLDecoder.decode(path, "utf-8");
		} catch (UnsupportedEncodingException e) {
			
			e.printStackTrace();
		}
		return path;
	}
}
